<?php $CI =& get_instance()?>
<h2 class="dialog_title"><span>Rata - rata Point Departemen</span></h2>
<div class="dialog_content" style="padding: 10px 20px; width:700px">
<?php $CI->load->model(array('departemen_model','jabatan_model','karyawan_history_jabatan_model','penilaian_model'))?>
<?php $res = $CI->departemen_model->select_by_id($dep_id)?>
<?php $res = (array)$res->row()?>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
	  <td>Departemen : </td>
	  <td><strong><?php echo $res['dep_nama'] ?></strong></td>
    </tr>
	<tr>
		<td width="80">Periode : </td>
		<td><strong><?php echo $month ?> - <?php echo $year ?></strong></td>
	</tr>
</table>
<?php $z=0;?>
<table class="zebraable" width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr class="header">
  	<td align="left"><span class="colorWhite">No</span></td>
  	<td align="left"><span class="colorWhite">Tgl Pengesahan</span></td>
    <td align="left"><span class="colorWhite">Jenis</span></td>
    <td align="left"><span class="colorWhite">Bidang</span></td>
    <td align="left"><span class="colorWhite">Tingkat</span></td>
    <td align="left"><span class="colorWhite">Kategori</span></td>
    <td align="right"><span class="colorWhite">Perbuatan Ke</span></td>
    <td align="right"><span class="colorWhite">Point</span></td>  
  </tr>
  <tbody id="searchKary-table" style="overflow:scroll; height:200px; max-heigh:500px" >
<?php
	//kumpulkan jabatan yang berada dalam departemen $departemenID
	$jbtData = $CI->jabatan_model->get_where("dep_id='$dep_id'");
	$jbtList = "";
	foreach ($jbtData->result_array() as $jbt){
		$jbtList .= ($jbtList? "," : "")."'$jbt[jbt_id]'";
	}
	$jbtList = $jbtList? $jbtList : "''";
	
	//kia cari dalam tabel karyawan_history_jabatan
	$karyJbtData = $CI->karyawan_history_jabatan_model->get_where("jbt_id IN ($jbtList)");
	$karyJbtList = "";
	foreach ($karyJbtData->result_array() as $karyJbt){
		$karyJbtList .= ($karyJbtList? "," : "")."'$karyJbt[kary_jbt_id]'";
	}
	$karyJbtList = $karyJbtList? $karyJbtList : "''";
	
	$CI->penilaian_model->join('prestasi_pelanggaran_detil','prestasi_pelanggaran_detil.detachiev_id=penilaian.detachiev_id');
	$CI->penilaian_model->join('prestasi_pelanggaran','prestasi_pelanggaran.achiev_id=prestasi_pelanggaran_detil.achiev_id');
	$CI->penilaian_model->join('karyawan','karyawan.kary_id=penilaian.kary_id');
	$CI->penilaian_model->join('karyawan_history_jabatan','karyawan_history_jabatan.kary_jbt_id=penilaian.kary_jbt_id');
	$CI->penilaian_model->join('jabatan','jabatan.jbt_id=karyawan_history_jabatan.jbt_id');
	$CI->penilaian_model->join('departemen','departemen.dep_id=jabatan.dep_id');
	$CI->penilaian_model->order_by('karyawan.kary_nama asc');
	$penilaianData = $CI->penilaian_model->get_where("penilaian.kary_jbt_id IN ($karyJbtList) ".
				"AND year(point_tgl_aktif)='$year' AND month(point_tgl_aktif)='$month'");
		
	$pointCount = 0;
	$jmlPerbuatan = 0;
	$karyID = 0;
?>
<?php if ($penilaianData->num_rows()>0):?>
	<?php foreach ($penilaianData->result_array() as $row): ?>
	<?php $pointCount += $row['point_point']; $jmlPerbuatan++;?>
	<?php if (!$karyID || $karyID != $row['kary_id']): ?>
		<tr class="notification">
			<td colspan="8"><?php echo $row['kary_nama']?> (<?php echo $row['kary_id']?>)</td>
			<?php $karyID = $row['kary_id']?>
		</tr>
	<?php endif ?>

		<tr  <?php if($z++%2==0):?>class="zebra"<?php endif?>>
			<td><?php echo $z?></td>
			<td><?php echo $row['point_tgl_aktif']?></td>
			<td><?php echo $jenis_options[$row['achiev_jenis']]?></td>
			<td><?php echo $row['achiev_bidang']?></td>
			<td><?php echo $tingkat_options[$row['detachiev_tingkat']]?></td>
			<td><?php echo $row['detachiev_nama']?></td>
			<td align="right"><?php echo $row['point_count']?></td>
			<td align="right"><?php echo $row['point_point']?></td>
		</tr>
	<?php endforeach?>
<?php else : ?>
	<tr>
		<td colspan="8" align="center"><strong>tidak ada data</strong></td>
	</tr>
<?php endif;?>
  </tbody>
  <tr class="header">
    <th align="right" colspan="7"><span class="colorWhite">Jumlah Point : </span></th>
    <th align="right"><span class="colorWhite"><?php echo number_format($pointCount,2) ?></span></th>  
  </tr>
  <tr class="header">
    <th align="right" colspan="7"><span class="colorWhite">Jumlah Laporan : </span></th>
    <th align="right"><span class="colorWhite"><?php echo number_format($jmlPerbuatan,2) ?></span></th>  
  </tr>
  <tr class="header">
    <th align="right" colspan="7"><span class="colorWhite">Rata - rata Point Departemen : </span></th>
    <th align="right"><span class="colorWhite"><?php echo number_format($jmlPerbuatan? $pointCount/$jmlPerbuatan : 0, 2) ?></span></th>  
  </tr>
</table>
</div>
<div class="dialog_buttons"><input type="button" value="Close" name="close" onclick="FBModal_hide()" /></div>